angular.module('contentApp').config(['$locationProvider', '$routeProvider', 'momentPickerProvider', '$stateProvider',

    function config($locationProvider, $routeProvider, $momentPickerProvider, $stateProvider) {
        $stateProvider.state('/', {
            url: '',
            template: '<login></login>'
        }).state('login', {
            url: '/login',
            template: '<login></login>',
            css: ['css/login.css']
        }).state('exam', {
            url: '/exam',
            template: '<exam></exam>',
            css: ['css/examination.css']
        }).state('question-list', {
            url: '/question-list',
            template: '<question-list></question-list>'
        }).state('result', {
            url: '/result',
            params: {
                score: null
            },
            template: '<result></result>'
        }).state('add-question', {
            url: '/add-question',
            template: '<add-question></add-question>',
        }).state('401', {
            templateUrl: 'components/status/401.html'
        }).state('403', {
            templateUrl: 'components/status/403.html'
        }).state('404', {
            templateUrl: 'components/status/404.html'
        }).state('500', {
            templateUrl: 'components/status/500.html'
        });

        $momentPickerProvider.options({
            locale: 'zh-cn'
        });

    }
]);


/**
 * 错误统一处理
 */
angular.module('contentApp')
    .factory('ErrorService', ['$injector', function ($injector) {
        function error(error) {
            if (error.status === 404) {
                $injector.get('$state').transitionTo('404');
            } else if (error.status == 401) {
                $injector.get('$state').transitionTo('401');
            } else if (error.status == 403) {
                $injector.get('$state').transitionTo('403');
            } else {
                $injector.get('$state').transitionTo('500');
            }
        }

        return {
            error: error
        };
    }]);